//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    class Algorithm: IOfficeXmlSerializable
    {
        List<Parameter> _parameters = new List<Parameter>();
        private OfficeArtExtensionList _extLst;
        private int _rev;
        private AlgorithmType? _type;

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("alg"))
            {
                _type = c.GetOptionalEnum<AlgorithmType>("type");
                _rev = c.GetOptionalInteger("rev", 0);
                _parameters.Clear();
                _parameters.AddRange(c.ReadOptionalWhile<Parameter>("param"));
                _extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }

        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("alg"))
            {
                c.SetOptionalEnum<AlgorithmType>("type", _type);
                c.SetOptionalInteger("rev", _rev, 0);
                c.WriteElements(_parameters);
                c.WriteOptionalElement(_extLst);
            }
        }
    }
}